Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





#Java - Code Snippets for '#File class' - 5 code snippet(s) found

 Sample 1. Method to check if the the file exists and not a directory

public static boolean isOleFile(File file)
{
   if ((file == null) || (!file.exists()) || (file.isDirectory())) {
      return false;
   }

   return true;
}

   Like      Feedback     file handling  check if file exists  File class  check if file is a directory  file.isDirectory  file.exists


 Sample 2. Code Sample / Example / Snippet of org.apache.bcel.classfile.JavaClass

    public void testMethodAnnotations() throws ClassNotFoundException

{

final JavaClass clazz = getTestClass(PACKAGE_BASE_NAME+".data.SimpleAnnotation");

final Method m = getMethod(clazz, "fruit");

final AnnotationDefault a = (AnnotationDefault) findAttribute(

"AnnotationDefault", m.getAttributes());

final SimpleElementValue val = (SimpleElementValue) a.getDefaultValue();

assertTrue("Should be STRING but is " + val.getElementValueType(), val

.getElementValueType() == ElementValue.STRING);

assertTrue("Should have default of bananas but default is "

+ val.getValueString(), val.getValueString().equals("bananas"));

}


   Like      Feedback      org.apache.bcel.classfile.JavaClass


 Sample 3. Code Sample / Example / Snippet of org.apache.bcel.classfile.ClassParser

    private void testJar(final File file) throws Exception {

System.out.println(file);

try (JarFile jar = new JarFile(file)) {

final Enumeration<JarEntry> en = jar.entries();

while (en.hasMoreElements()) {

final JarEntry e = en.nextElement();

final String name = e.getName();

if (name.endsWith(".class")) {

try (InputStream in = jar.getInputStream(e)) {

final ClassParser parser = new ClassParser(in, name);

final JavaClass jc = parser.parse();

for (final Method m : jc.getMethods()) {

compare(name, m);

}

}

}

}

}

}


   Like      Feedback      org.apache.bcel.classfile.ClassParser


 Sample 4. Code Sample / Example / Snippet of org.apache.bcel.classfile.ConstantClass

    public String getEnumTypeString()

{

return ((ConstantUtf8) getConstantPool().getConstant(typeIdx))

.getBytes();

}


   Like      Feedback      org.apache.bcel.classfile.ConstantClass


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
 Sample 5. Code Sample / Example / Snippet of org.apache.bcel.classfile.InnerClasses

public Attribute copy(final ConstantPool _constant_pool) {
final InnerClasses c = (InnerClasses) clone();
c.inner_classes = new InnerClass[inner_classes.length];
for (int i = 0; i < inner_classes.length; i++) {
c.inner_classes[i] = inner_classes[i].copy();
}
c.setConstantPool(_constant_pool);
return c;
}

   Like      Feedback      org.apache.bcel.classfile.InnerClasses  object initialization using clone



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner